package jay.home.templates;

import java.util.*;
import jay.home.utils.*;

public class ActionTemplate
{
  protected static String nl;
  public static synchronized ActionTemplate create(String lineSeparator)
  {
    nl = lineSeparator;
    ActionTemplate result = new ActionTemplate();
    nl = null;
    return result;
  }

  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "package jay.home.bet.web.struts;" + NL + "" + NL + "import javax.servlet.http.HttpServletRequest;" + NL + "import javax.servlet.http.HttpServletResponse;" + NL + "" + NL + "import jay.home.bet.domain.logic.BetFacade;" + NL + "" + NL + "import org.apache.struts.action.ActionForm;" + NL + "import org.apache.struts.action.ActionForward;" + NL + "import org.apache.struts.action.ActionMapping;" + NL + "" + NL + "public class ";
  protected final String TEXT_2 = "Action extends BaseAction " + NL + "{" + NL + "\tpublic ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception " + NL + "\t{" + NL + "\t\tBetFacade bet = getBetFacade();" + NL + "\t\t";
  protected final String TEXT_3 = "ActionForm aform = (";
  protected final String TEXT_4 = "ActionForm)form;" + NL + "\t\tString username = request.getRemoteUser();" + NL + "\t\t" + NL + "\t\ttry" + NL + "\t\t{" + NL + "\t\t\t//todo" + NL + "\t\t}catch(Exception e)" + NL + "\t\t{" + NL + "\t\t\tmapping.findForward(\"error\");" + NL + "\t\t}" + NL + "\t\t" + NL + "\t    return mapping.findForward(\"success\");" + NL + "\t}" + NL + "}";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    
  String action = (String)argument;

    stringBuffer.append(TEXT_1);
    stringBuffer.append(StringUtils.capitalize(action));
    stringBuffer.append(TEXT_2);
    stringBuffer.append(StringUtils.capitalize(action));
    stringBuffer.append(TEXT_3);
    stringBuffer.append(StringUtils.capitalize(action));
    stringBuffer.append(TEXT_4);
    return stringBuffer.toString();
  }
}
